var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    serchList: [],
    zimu: ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'],
    conts: [],
    title:"",
    a_id: "",
    j_id: "",
    id:"",
    f_id:"",
    back_orser:"",
    hiddenmodalput: false,
  },
  // 修改分组
  edit_name: function (e) {
    this.setData({
      hiddenmodalput: !this.data.hiddenmodalput,
      id:e.currentTarget.dataset.id
    })
  },
  cancel: function () {
    this.setData({
      hiddenmodalput: false
    })
  },
  confirm: function (e) {
    var that = this;
    var title = that.data.title;
    that.setData({
      hiddenmodalput: false
    })
    app.util.request({
      'url':"entry/wxapp/follow.update_fenzu",
      data:{
        id:that.data.id,
        title:title
      },
      success:function(res)
      {
        wx.showToast({
          title: res.data.message,
          icon: "none"
        })
        that.getzhuanjiafenzu();
      }
    })
    
  },
  fzname_input: function (e) {
    console.log(e)
    this.setData({
      title: e.detail.value
    })
  },
  // 删除分组
  splice_fz: function (e) {
    var that = this;
    var id = e.currentTarget.dataset.id;
    var count = e.currentTarget.dataset.count;
    if(count > 0)
    {
      wx.showModal({
        title:'提示',
        content:'该分组已有用户,暂不支持删除'
      })
    }else{
      wx.showModal({
        title: '提示',
        content: '确定删除当前分组吗？',
        success: function (res) {
          if (res.confirm) {
            app.util.request({
              'url':"entry/wxapp/follow.del_fenzus",
              data:{
                id:id
              },
              success:function(res)
              {
                wx.showToast({
                  title: res.data.message,
                  icon:"none"
                })
                that.getzhuanjiafenzu();
              }
            })
            
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    }
    
  },
  zimu_btn: function (e) {
    var zimu = e.currentTarget.dataset.cont
    console.log(zimu)
    this.setData({
      toView: zimu
    })
  },
  add: function () {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/fenzu/fenzu?zid=' + this.data.zid,
    })
  },
  // 选择分组
  choose: function (e) {
    var biaoqian = e.currentTarget.dataset.biaoqian

    var that = this;
    var zid = that.data.zid
    var a_id = that.data.a_id;
    var j_id = that.data.j_id;
    wx.showModal({
      title: '提示',
      content: "是否选择该分组",
      success: function (con) {
        if (con.confirm) {
          app.util.request({
            'url': "entry/wxapp/follow.set_fenzu",
            data: {
              type: biaoqian,
              zid: zid,
              id: a_id,
              j_id: j_id,
            },
            success: function (res) {
              wx.showModal({
                cancelColor: '提示',
                content:"是否分配随访",
                success:function(con)
                {
                  if(con.confirm)
                  {
                    wx.navigateTo({
                      url: '/hyb_yl/doctorHome/pages/acceptpatient/acceptpatient?id='+a_id+'&typs=order&back_orser='+that.data.back_orser+'&j_id='+j_id+'&zid='+zid,
                    })
                  }else{
                    setTimeout(function () {
                      wx.navigateBack({})
                    }, 500)
                  }
                }
              })
              
            }
          })
        }
      }
    })
  },
  go_date: function (e) {
    var that = this
    var biaoqian = e.currentTarget.dataset.biaoqian
    var zid = that.data.zid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/huanzhe/huanzhe?type=' + biaoqian + '&zid=' + zid,
    })
  },
  go_date_one: function (e) {
    var that = this
    var zid = that.data.zid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/huanzhe/huanzhe?type=0&zid=' + zid,
    })
  },
  serch: function (e) {
    var serch_text = e.detail.value
    var conts = this.data.conts
    console.log(conts)
    var arr = []
    for (var i = 0; i < conts.length; i++) {
      console.log(conts[i])
      for (var j = 0; j < conts[i].length; j++) {
        if (conts[i][j].title.indexOf(serch_text) != -1) {
          arr.push(conts[i][j])
        }
      }
    }
    this.setData({
      serchList: arr
    })
    if (serch_text == '') {
      this.setData({
        serchList: []
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this
    var zid = options.zid
    that.setData({
      zid: zid
    })
    // '/hyb_yl/mysubpages/pages/grouping_list/grouping_list?a_id='+id+'&j_id='+j_id+'&typs=fenzu'
    var a_id = options.a_id;
    var j_id = options.j_id;
    var typs = options.typs;
    if (typs != '' && typs != undefined && typs != 'undefined') {
      that.setData({
        a_id: a_id,
        j_id: j_id,
        typs: typs
      })
    }
    if(options.back_orser != 'undefined' && options.back_orser != undefined)
    {
      that.setData({
        f_id:options.f_id,
        back_orser:options.back_orser
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // this.getzhuanjiabiaoqian()
    this.getzhuanjiafenzu();
  },
  // 获取专家分组
  getzhuanjiafenzu: function () {
    var that = this;
    app.util.request({
      'url': "entry/wxapp/follow.zhuanjia_fenzu",
      data: {
        zid: that.data.zid
      },
      success: function (res) {
        that.setData({
          conts: res.data.list,
          weifenzu: res.data.weifenzu
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getList: function (index) {
    var that = this;
    var zid = that.data.zid
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.allkeshi',
      data: {
        zid: zid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          conts: res.data
        })
      }
    })
  },
  getzhuanjiabiaoqian() {
    var that = this;
    var zid = that.data.zid
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.biaoqian',
      data: {
        zid: zid
      },
      success: function (res) {
        console.log(res)
        that.setData({
          conts: res.data.fenzu,
          weifenzu: res.data.weifenzu,
          list: JSON.stringify(res.data.list),
        })
      }
    })
  }
})